欢迎来到传世资源网!
加载中...
正在加载,请耐心等待...
本站为收藏、学习站,如有侵权,请联系管理员删除!

android_百度地图_示例源码(内嵌html5实现)_

介绍 评论 失效链接反馈

android_百度地图_示例源码(内嵌html5实现)_ Android平台开发-第1张android_百度地图_示例源码(内嵌html5实现)_ Android平台开发-第2张

package com.example.location;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

/**
 * 获取当前位置
 * @author yy
 *
 */
public class BdLocationDemo extends Plugin {
	public static final String ACTION = "location";
	private LocationClient mLocationClient = null;
	private JSONObject jsonObj = new JSONObject();
	private PluginResult result = null;

	@Override
	public PluginResult execute(String action, JSONArray data, String callbackId) {
		if (ACTION.equals("location")) {
			try {
				cordova.getActivity().runOnUiThread(new RunnableLoc());

			} catch (Exception e) {
			}

		} else {
			mLocationClient.stop();
			result = new PluginResult(PluginResult.Status.OK);
		}
		while (this.result == null) {
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {

				e.printStackTrace();
			}
		}
		return result;
	}

	@Override
	public void onDestroy() {
		if (mLocationClient != null && mLocationClient.isStarted()) {
			mLocationClient.stop();
			mLocationClient = null;
		}
		super.onDestroy();
	}

	/**
	 * @author Zhang Rong
	 * @date: 2012-12-23 涓婂崍11:27:25
	 * @version 1.0
	 */
	class RunnableLoc implements Runnable {
		public void run() {
			mLocationClient = new LocationClient(cordova.getActivity());
			LocationClientOption option = new LocationClientOption();
			option.setOpenGps(true);
			option.setCoorType("bd09ll");
			option.setPriority(LocationClientOption.NetWorkFirst);
			option.setProdName("BaiduLoc");
			option.setScanSpan(5000);
			mLocationClient.setLocOption(option);
			mLocationClient.registerLocationListener(new BDLocationListener() {

				public void onReceiveLocation(BDLocation location) {
					if (location == null) {
						return;
					}
					StringBuffer sb = new StringBuffer(256);
					if (location.getLocType() == BDLocation.TypeGpsLocation) { // GPS鎯呭喌
						sb.append("\nSpeed : ");
						sb.append(location.getSpeed());
						sb.append("\nSatellite : ");
						sb.append(location.getSatelliteNumber());
					} else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
						sb.append("\nAddress : ");
						sb.append(location.getAddrStr());
						try {
//							jsonObj.put("add", location.getAddrStr());
							//经、纬度坐标
							jsonObj.put("poi", location.getLongitude() "," location.getLatitude());
							result = new PluginResult(PluginResult.Status.OK,
									jsonObj);
							System.out.println(location.getAddrStr());
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}
				}

				public void onReceivePoi(BDLocation location) {
				}

			});
			mLocationClient.start();
		}

	}

}

下载声明:

本站资源均有第三方用户自行上传分享推荐,非本站自制,仅供玩家做交流学习之用!切勿用于商业用途!游戏作品版权归原作者享有,如有版权问题,请附带版权证明至邮件,本平台将应您的要求删除。
相关推荐:

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复